package com.wanmait.gohome.controller.web;


import com.github.pagehelper.PageInfo;
import com.wanmait.gohome.pojo.Comment;
import com.wanmait.gohome.pojo.Information;
import com.wanmait.gohome.pojo.Journal;
import com.wanmait.gohome.pojo.Userinfo;
import com.wanmait.gohome.service.CommentService;
import com.wanmait.gohome.service.InformationService;
import com.wanmait.gohome.service.JournalService;
import com.wanmait.gohome.service.TaskService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentService commentService;
    @Resource
    private JournalService journalService;
    @Resource
    private TaskService taskService;


    @RequestMapping("remark")//添加评论
    @ResponseBody
    public void remark(String text,String rzid,HttpServletRequest request)
    {
//        Userinfo userinfo = (Userinfo) request.getSession().getAttribute("userinfo");
        int id=Integer.parseInt(rzid);
        Comment comment = new Comment();
        comment.setUserinfoId(2);
        comment.setJournalId(id);
        comment.setRemark(text);
        commentService.insert(comment);//添加评论
        journalService.update(id);

    }

    @RequestMapping("listAll")//添加评论
    public ModelAndView listAll(String id)
    {
        int ids=Integer.parseInt(id);
        PageInfo<Comment> comments = commentService.findAllById(ids);
//        List<Comment> comments = commentService.findAllById(ids);
        ModelAndView mv = new ModelAndView();
        mv.addObject("comments",comments);
        mv.setViewName("web/blogger/listAll");
        return mv;
    }



}
